/*** 本文件由CSMIS2.0-ModelCreater(UTF-8)工具辅助生成，版本1.0 ***/

package com.ce.pub.message.logic.search;

import java.sql.ResultSet;
import java.sql.SQLException;

import com.ce.framework.datamaintain.logic.ISQLMapper;
import com.ce.framework.datamaintain.logic.SQLSearchCondition;
import com.ce.framework.exception.AppException;
import com.ce.framework.util.StringUtil;
import com.ce.pub.message.view.PubMessageView;

/**
* 嫦娥软件有限公司 版权所有 2013
* 创建人：　andy
* 创建日期：2010-11-06
* 创建时间：09:07:50
* 功能描述：短消息 [PUB_T_MESSAGE]条件过滤类
* ==============================================
* 修改历史
* 修改人		修改时间		修改原因
*
* ==============================================
*/
public class PubMessageSearchCondition  extends SQLSearchCondition
	implements ISQLMapper
{

	private String sendUser;
	private String receiveUser;
	private String beginDate;
	private String endDate;
	
	/*
	 * 使用js框架分页时进行排序的必要属性
	 */
	private String order;   //排序方法
	private String sort;  //排序字段


	public String getOrder() {
		return order;
	}

	public void setOrder(String order) {
		this.order = order;
	}


	public String getSort() {
		return sort;
	}

	public void setSort(String sort) {
		this.sort = sort;
	}

	public String getSearchSql() throws AppException {
		
		StringBuffer sql = new StringBuffer("select t.*,p1.vc_name as sendusername ,p2.vc_name as receiveusername from " +
				"PUB_T_MESSAGE t ,sys_t_person p1,sys_t_person p2 where t.vc_send$user = p1.vc_id(+) and t.vc_receive$user = p2.vc_id(+) and  t.VC_DEL$FLAG = 0 " +
				"and ((t.VC_SEND$USER = '"+this.getSafeValue(this.sendUser)+"' and t.VC_RECEIVE$USER = '"+this.getSafeValue(this.receiveUser)+"') " +
				"or  (t.VC_RECEIVE$USER = '"+this.getSafeValue(this.sendUser)+"' and t.VC_SEND$USER = '"+this.getSafeValue(this.receiveUser)+"'))");
		//实现排序的代码
		if(StringUtil.isNotBlank(this.order)){
			if("dtTime".equals(this.sort)){
				sql.append("  order by t.DT_TIME "+this.order);
			}	
		}else{
			sql.append("  order by t.DT_TIME desc ");
		}
		return sql.toString() ;
	}
	
	public Object fromSQLQuery(ResultSet rs, int num) {
		PubMessageView view = new PubMessageView();
		try {
			view.setVcId(rs.getString("VC_ID"));
			view.setVcContent(rs.getString("VC_CONTENT"));
			view.setVcSendUser(rs.getString("VC_SEND$USER"));
			view.setVcReceiveUser(rs.getString("VC_RECEIVE$USER"));
			view.setDtTime(rs.getTimestamp("DT_TIME"));
			view.setIntSeeFlag(rs.getInt("INT_SEE$FLAG"));
			view.setVcDelFlag(rs.getInt("VC_DEL$FLAG"));
			view.setSendUserName(rs.getString("sendusername"));
			view.setReceiveUserName(rs.getString("receiveusername"));

		} catch (SQLException e) {
			
			e.printStackTrace();
		}
		return view;
	}
	
	public ISQLMapper getSQLMapper() {
		
		return this;
	}

	public String getSendUser() {
		return sendUser;
	}

	public void setSendUser(String sendUser) {
		this.sendUser = sendUser;
	}

	public String getReceiveUser() {
		return receiveUser;
	}

	public void setReceiveUser(String receiveUser) {
		this.receiveUser = receiveUser;
	}

	public String getBeginDate() {
		return beginDate;
	}

	public void setBeginDate(String beginDate) {
		this.beginDate = beginDate;
	}

	public String getEndDate() {
		return endDate;
	}

	public void setEndDate(String endDate) {
		this.endDate = endDate;
	}

}

